home *** CD-ROM | disk | FTP | other *** search
/ Aminet 45 / Aminet 45 (2001)(GTI - Schatztruhe)[!][Oct 2001].iso / Aminet / util / gnu / cvs-1.11.1p1.lha / contrib / dirfns.shar / opendir.c < prev    next >
Encoding:
C/C++ Source or Header  |  2001-02-28  |  675 b   |  36 lines

  1. /* Copyright (c) 1982 Regents of the University of California */
  2.  
  3. static char sccsid[] = "@(#)opendir.c 4.4 11/12/82";
  4.  
  5. #include <sys/types.h>
  6. #include <sys/stat.h>
  7. #include <dir.h>
  8.  
  9. /*
  10.  * open a directory.
  11.  */
  12. DIR *
  13. opendir(name)
  14.     char *name;
  15. {
  16.     register DIR *dirp;
  17.     register int fd;
  18.     struct stat statbuf;
  19.     char *malloc();
  20.  
  21.     if ((fd = open(name, 0)) == -1)
  22.         return NULL;
  23.     if (fstat(fd, &statbuf) == -1 || !(statbuf.st_mode & S_IFDIR)) {
  24.         close(fd);
  25.         return NULL;
  26.     }
  27.     if ((dirp = (DIR *)malloc(sizeof(DIR))) == NULL) {
  28.         close (fd);
  29.         return NULL;
  30.     }
  31.     dirp->dd_fd = fd;
  32.     dirp->dd_loc = 0;
  33.     dirp->dd_size = 0;    /* so that telldir will work before readdir */
  34.     return dirp;
  35. }
  36.